package com.traitswu.websocket.simple;

import javax.websocket.*;
import javax.websocket.server.ServerEndpoint;
import java.io.IOException;
import java.util.List;

/**
 * Created by xiaoquan on 17-5-23.
 */


@ServerEndpoint("/simple")
public class SimpleEndpoint {


    public SimpleEndpoint() {
        System.out.println("construct SimpleEndpoint");
    }

    @OnOpen
    public void open(Session session) {
        System.out.println("start:" + session.getId());

//        System.out.println(message + "," + last + "," + list);

        try {


            session.getBasicRemote().sendText("server accept connect!");
        } catch (IOException e) {
            e.printStackTrace();
        }

    }


    @OnClose
    public void end() {
        System.out.println("end:");

    }


    @OnMessage
    public void incoming(Session session, String message) {
        System.out.println("server message:" + message + "," + session.getId());

        try {
            session.getBasicRemote().sendText(message);
        } catch (IOException e) {
            e.printStackTrace();
        }

    }


    @OnError
    public void onError(Throwable t) throws Throwable {
        System.out.println("server error:" + t.getMessage());
    }


}
